# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# aim:    使用pillow进行图片的简单操作
# author: wangkaixuan
# email:  26554189525@qq.com 
# date:   2018/1/9

from PIL import Image,ImageFilter,ImageDraw,ImageFont
import random

im = Image.open('pic.jpg')
w,h = im.size
print('Original image size:%sx%s' %(w,h))
im.thumbnail((w/2,h/2))
print('Resize image size:%sx%s' %(w/2,h/2))
im.save('pic1.jpg')
im2 = im.filter(ImageFilter.BLUR)
im2.save('pic2.jpg')

def rndChar():
    return chr(random.randint(65,90))

def rndColor1():
    return (random.randint(135,255),random.randint(135,255),random.randint(135,255))

def rndColor2():
    return (random.randint(33,65),random.randint(33,65),random.randint(33,65))

width = 60 * 4
height = 60
image = Image.new('RGB',(width,height))
font = ImageFont.truetype('symbol.ttf',45)
draw = ImageDraw.Draw(image)
for x in range(width):
    for y in range(height):
        draw.point((x,y),fill=rndColor1())

for t in range(4):
    draw.text((60 * t + 10,2),rndChar(),font = font,fill = rndColor2())
# image = image.filter(ImageFilter.BL)
image.save('pic3.jpg')
